package com.fyt.reachgo.mapper;

import com.fyt.reachgo.domain.TravelGuide;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Update;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

/**
* @author 27675
* @description 针对表【travel_guide(旅行路书信息表（含UGC内容）)】的数据库操作Mapper
* @createDate 2025-02-25 08:37:04
* @Entity com.fyt.reachgo.domain.TravelGuide
*/
public interface TravelGuideMapper extends BaseMapper<TravelGuide> {

    /**
     * 增减路书点赞数
     * @param guideId 路书ID
     * @param increment 增量(正数为增加，负数为减少)
     * @return 影响的行数
     */
    @Update("UPDATE travel_guide SET likes = likes + #{increment} WHERE id = #{guideId}")
    int incrementLikes(@Param("guideId") Integer guideId, @Param("increment") int increment);

    // 批量更新点赞数
    @Update({
            "<script>",
            "<foreach collection='list' item='item' separator=';'>",
            "UPDATE travel_guide SET likes = #{item.likes} WHERE id = #{item.id}",
            "</foreach>",
            "</script>"
    })
    int batchUpdateLikes(@Param("list") List<TravelGuide> list);

    List<TravelGuide> tanTList(Long userId);
}



